﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.WindowsAzure.StorageClient;
using Microsoft.WindowsAzure;
using Web.Models;
using Microsoft.WindowsAzure.ServiceRuntime;

namespace Web.Services
{
    public class SaudoContext : TableServiceContext
    {
        public static SaudoContext Default()
        {
            string connectionString = RoleEnvironment.GetConfigurationSettingValue("storage");
            CloudStorageAccount account = CloudStorageAccount.Parse(connectionString);
            CloudTableClient.CreateTablesFromModel(
                typeof(SaudoContext),
                account.TableEndpoint.AbsoluteUri,
                account.Credentials);
            return new SaudoContext(account.TableEndpoint.AbsoluteUri, account.Credentials);
        }

        public SaudoContext(string address, StorageCredentials credentials)
            : base(address, credentials)
        {

        }

        public IQueryable<Saudo> Saudos
        {
            get
            {
                return CreateQuery<Saudo>("Saudos");
            }
        }

        public IQueryable<Comment> Comments
        {
            get
            {
                return CreateQuery<Comment>("Comments");
            }
        }
    }
}